package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }
    /**
     * 床位创建
     * @param dto
     * @return
     */
    @ApiOperation("新增床位")
    @ApiImplicitParam(name = "dto", value = "床位dto对象", dataType = "BedDto")
    @ApiOperationSupport(includeParameters = {"dto.bedNumber", "dto.roomId", "dto.sort"})
    @PostMapping("/create")
    public ResponseResult createBed(@RequestBody BedDto dto){
        bedService.createBed(dto);
        return ResponseResult.success();
    }
    /**
     * 根据id查询床位
     */
    @ApiOperation("根据id查询床位")
    @GetMapping("/read/{id}")
    public ResponseResult<BedVo> readById(@PathVariable Long id){
        BedVo vo = bedService.readById(id);
        return success(vo);
    }
    /**
     * 更新床位
     */
    @ApiOperation("更新床位")
    @PutMapping("/update")
    public ResponseResult updateBed(@RequestBody BedDto dto){
        bedService.updateBed(dto);
        return success();
    }
    /**
     * 删除床位
     */
    @ApiOperation("删除床位")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@ApiParam(name = "id", value = "床位注解id", required = true) @PathVariable Long id){
        bedService.deleteById(id);
        return success();
    }






}
